package com.springboot.web.controller;

import com.springboot.web.common.CommonResult;
import com.springboot.web.entity.Address;
import com.springboot.web.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/address")
@Slf4j
@RestController
public class AddressController {

    @Resource
    private AddressService addressService;

    @GetMapping
    public List<Address> queryAll () {
        return addressService.queryAll();
    }

    @GetMapping("/{addressId}")
    public Address queryById (@PathVariable Integer addressId) {
        return addressService.queryById(addressId);
    }

    @PostMapping
    public CommonResult addOne (@RequestBody Address address) {
        addressService.addOne(address);
        return new CommonResult(0,"success",null);
    }

    @PutMapping
    public CommonResult modify (@RequestBody Address address) {
        addressService.modify(address);
        return new CommonResult<>(0,"success",null);
    }

    @DeleteMapping
    public CommonResult deleteOne (@RequestParam("address_id") Integer id) {
        addressService.deleteOne(id);
        return new CommonResult<>(0,"success",null);
    }
}
